package all;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author by zhangleishuidihuzhu.com
 * @Date 2023/5/27 17:44
 */
public class HW {

    public static void main(String[] args) {
        HW h = new HW();
//        System.out.println(h.ipv4ToNum("1#0#0#0"));
        int[][] arr = new int[][]{{46,89},{50,53},{52,68},{72,45},{77,81}};
        System.out.println(h.die(arr));
    }

    /**
     * 叠书
     */
    private int die(int[][] arr) {

        Arrays.stream(arr).sorted((o1, o2) -> {
            if(o1[0]!=o2[0]) {
                return o1[0] - o2[0];
            }else {
                return o2[1] - o1[1];
            }
        });
//        //排序
        for(int i = 0; i< arr.length; i++) {
            for(int j = i+1; j< arr.length; j++) {
                int[] cur = arr[i];
                int[] sec = arr[j];
                if(cur[0]<sec[0] || (cur[0] == sec[0] && cur[1]<sec[1])) {
                    int[] temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }

        int result = 1;
        int[] before = arr[0];
        for(int i = 1; i<arr.length; i++) {
            int[] cur = arr[i];
            if(cur[0]<before[0] && cur[1]<before[1]) {
                result++;
                before = cur;
            }
        }

        return result;
    }

    /**
     * ipv4地址转换为 整数
     */
    private long ipv4ToNum(String ipv4) {
        //check 空串
        String[] arr = ipv4.split("#");
        if(arr.length != 4) {
            //抛错
        }

        //先转 16进制 再转10进制
        String s = "0x";
        for (int i = 0; i < arr.length; i++) {
            s = s + convertToSix(arr[i]);
        }

        return convertToTen(s);
    }

    private long convertToTen(String s) {
        char[] arr = s.toCharArray();
        long result = 0;
        for (int i = 2; i < arr.length; i++) {
            char cur = arr[i];
            if('A' == cur) {
                result = result*16 + 10;
            }else if('B' == cur) {
                result = result*16 + 11;
            }else if('C' == cur) {
                result = result*16 + 12;
            }else if('D' == cur) {
                result = result*16 + 13;
            }else if('E' == cur) {
                result = result*16 + 14;
            }else if('F' == cur) {
                result = result*16 + 15;
            }else {
                result = result*16 + (cur - '0');
            }
        }
        return result;
    }

    //128 0 255 255
    private String convertToSix(String s) {
        String result = "";
        int cur = Integer.parseInt(s);
        if(cur == 0) {
            return "00";
        }
        while (cur>16) {
            int num = cur/16;
            cur = cur-num*16;
            if(num == 15) {
                result += "F";
            }else if(num == 14) {
                result += "E";
            }else if(num == 13) {
                result += "D";
            }else if(num == 12) {
                result += "C";
            }else if(num == 11) {
                result += "B";
            }else if(num == 10) {
                result += "A";
            }else {
                result += num;
            }
        }
        if(cur>=0) {
            if(cur == 15) {
                result += "F";
            }else if(cur == 14) {
                result += "E";
            }else if(cur == 13) {
                result += "D";
            }else if(cur == 12) {
                result += "C";
            }else if(cur == 11) {
                result += "B";
            }else if(cur == 10) {
                result += "A";
            }else {
                result += cur;
            }
        }
        return result;
    }
}
